package com.liang.mianshiweb;

public class DeadLock {
	public static void main(String[] args) {
		Object a = new Object();
		Object b = new Object();
		new Thread(()->{
			synchronized (a) {
				System.out.println(Thread.currentThread().getName()+" get a");
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println(Thread.currentThread().getName()+" want get b");
				synchronized (b) {
					System.out.println(Thread.currentThread().getName()+" get b");
				}
			}
		}).start();
		new Thread(()->{
			synchronized (b) {
				System.out.println(Thread.currentThread().getName()+" get b");
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println(Thread.currentThread().getName()+" want get a");
				synchronized (a) {
					System.out.println(Thread.currentThread().getName()+" get a");
				}
			}
		}).start();
	}
}